<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="所属用户:" prop="user_id" v-if="false">
                    <el-input-number v-model="form.user_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="合作方ID:" prop="partner_id" v-if="false">
                    <el-input-number v-model="form.partner_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="缴纳记录:" prop="bond_id" v-if="false">
                    <el-input-number v-model="form.bond_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="类型:" prop="type">
                    <el-radio-group v-model="form.type">
                        <el-radio v-for="(item, index) in type" :key="index" :label="item.value">{{ item.label }}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="收支金额:" prop="money">
                    <el-input-number v-model="form.money" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="收入前金额:" prop="money_after" v-if="false">
                    <el-input-number v-model="form.money_after" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="收入后金额:" prop="money_before" v-if="false">
                    <el-input-number v-model="form.money_before" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="备注:" prop="remark">
                    <el-input type="textarea" rows="4" v-model="form.remark" placeholder="请输入备注" clearable />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
        extForm: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                user_id: [{ required: true, message: "请输入所属用户", trigger: "blur" }],
                partner_id: [{ required: true, message: "请输入合作方ID", trigger: "blur" }],
                bond_id: [{ required: true, message: "请输入缴纳记录", trigger: "blur" }],
                money: [{ required: true, message: "请输入收支金额", trigger: "blur" }],
                money_after: [{ required: true, message: "请输入收入前金额", trigger: "blur" }],
                money_before: [{ required: true, message: "请输入收入后金额", trigger: "blur" }],
                // remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
            },
            form: {
                type: 1
            },
            // 区域选择配置
            areaOptions: regionData,
            type:[
               { label: "增加", value: 1 },
               { label: "减少", value: 2 },
            ],
        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },
        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', {
                        ...this.extForm,
                        ...this.form
                    })
                }
            })
        },
        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
